/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.qmul.ns2.line;

import edu.qmul.ns2.computer.NodeLabel;
import java.awt.BasicStroke;
import java.awt.Component;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import me.zhy.swing.AWTUtilities;
import me.zhy.swing.LineSegmentComponent;

/**
 *
 * @author Moon
 */
public class ExtendLineSegmentComponent extends LineSegmentComponent {

    private final NodeLabel first;
    private final NodeLabel last;
    private int linkType;
    private double bandWidth;
    private double delay;
    private String queueType;
    private double linkCost;

    public ExtendLineSegmentComponent(final NodeLabel first, final NodeLabel last,int lt) {
        this.first = first;
        this.last = last;
        this.linkType = lt;
        if(linkType == LinkType.commonLink){
            super.setDash(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND,
                3.5f, new float[]{15, 10,}, 0f));
        }if(linkType == LinkType.duplexLink){
            super.setDash(new BasicStroke(3.5f));
        }if(linkType == LinkType.simplexLink){
            super.setDash(new BasicStroke(2.5f));
        }
        setLocation(first.getX() + first.getWidth() / 2, first.getY() + first.getHeight() / 2, last.getX() + last.getWidth() / 2, last.getY() + last.getHeight() / 2);
        ComponentAdapter listener = new ComponentAdapter() {

            @Override
            public void componentResized(ComponentEvent e) {
                componentMoved(e);
            }

            @Override
            public void componentMoved(ComponentEvent e) {
                setLocation(first.getX() + first.getWidth() / 2, first.getY() + first.getHeight() / 2, last.getX() + last.getWidth() / 2, last.getY() + last.getHeight() / 2);
            }

            @Override
            public void componentHidden(ComponentEvent e) {
                first.removeComponentListener(this);
                last.removeComponentListener(this);
                AWTUtilities.remove(ExtendLineSegmentComponent.this);
            }
        };
        first.addComponentListener(listener);
        last.addComponentListener(listener);
    }

    public Component getFirst() {
        return first;
    }

    public Component getLast() {
        return last;
    }

    /**
     * @return the bandWidth
     */
    public double getBandWidth() {
        return bandWidth;
    }

    /**
     * @param bandWidth the bandWidth to set
     */
    public void setBandWidth(double bandWidth) {
        this.bandWidth = bandWidth;
    }

    /**
     * @return the delay
     */
    public double getDelay() {
        return delay;
    }

    /**
     * @param delay the delay to set
     */
    public void setDelay(double delay) {
        this.delay = delay;
    }

    /**
     * @return the queueType
     */
    public String getQueueType() {
        return queueType;
    }

    /**
     * @param queueType the queueType to set
     */
    public void setQueueType(String queueType) {
        this.queueType = queueType;
    }

    /**
     * @return the linkCost
     */
    public double getLinkCost() {
        return linkCost;
    }

    /**
     * @param linkCost the linkCost to set
     */
    public void setLinkCost(double linkCost) {
        this.linkCost = linkCost;
    }

    /**
     * @return the linkType
     */
    public int getLinkType() {
        return linkType;
    }
    
}
